﻿using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Runtime.InteropServices;

using ZoneFiveSoftware.Common.Visuals;

namespace PolarImport.Settings
{
   
    
    /// <summary>
    /// the controls and their behaviour shown on the settingspage
    /// </summary>
    public partial class PolarImportSettings : UserControl
    {
        private class ContentProvider : TreeList.DefaultContentProvider
        {
            public override IList GetChildren(object parentElement)
            {
                if (parentElement is PolarSeries)
                {
                    ArrayList childDevices = new ArrayList();
                    foreach (PolarDevice device in Settings.SupportedDevices)
                    {
                        if ( parentElement.ToString() == device.PolarSerie.ToString())
                            childDevices.Add(device);
                    }
                    return childDevices;
                }

                return null;
            }
            public override object GetParent(object element)
            {
                if (element is PolarDevice)
                {
                    PolarDevice thisElement = (PolarDevice)element;
                    return thisElement.PolarSerie;
                }

                return null;
            }

            public override bool HasChildren(object element)
            {
                return true;
            }
        }
        
        public PolarImportSettings()
        {
            InitializeComponent();
            // Setup the TreeList of supported devices
            treeList1.Columns.Add(new TreeList.Column("PolarSerie", "Series", 80, StringAlignment.Near));
            treeList1.Columns.Add(new TreeList.Column("Monitor", "Monitor", 100, StringAlignment.Near));
            treeList1.Columns.Add(new TreeList.Column("Modells", "Modells", 140, StringAlignment.Near));
            treeList1.RowData = Settings.SupportedDevices;
        }

        /// <summary>
        /// Handles the LinkClicked event of the checkForUpdates control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.LinkLabelLinkClickedEventArgs"/> instance containing the event data.</param>
        private void checkForUpdates_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string url = "http://www.tmbike.de/index2.php?option=com_versions&catid=1&myVersion=" + 
                GetType().Assembly.GetName().Version.ToString(4);
            Process.Start(url);
        }

        /// <summary>
        /// Localizes the texts.
        /// </summary>
        internal void LocalizeTexts() 
        {
            this.checkForUpdates.Text = Properties.Resources.PolarImport_Settings_CheckForUpdates;
        }

        internal void ThemeChange(ITheme visualTheme)
        {
        }

           
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string url = "http://tracker.tmbike.de";
            Process.Start(url);
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string url = "http://www.tmbike.de";
            Process.Start(url);
        }

      

    }
}
